package com.ruoyi.yey.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class GoodsService extends ServiceImpl<GoodsMapper,GoodsEntity> {

    /**
     * 分页+模糊查询
     * @param page
     * @param searchModel
     * @return
     */
    public Page<Map> findAllByPage(Page page, GoodsEntity searchModel) {
        return baseMapper.findBySearchVo(page,searchModel);
    }

    public List<Map> findByList(GoodsEntity searchVo) {
        return baseMapper.findBySearchVo(searchVo);
    }



    /**
     * 新增
     * @param goods
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(GoodsEntity goods) {
        baseMapper.insert(goods);
    }

    public GoodsEntity findById(int id){
        return baseMapper.selectById(id);
    }

    /**
     * 修改
     * @param goods
     */
    @Transactional(rollbackFor = Exception.class)
    public void edit(GoodsEntity goods){
        baseMapper.updateById(goods);
    }

    /**
     * 删除
     * @param id
     */
    @Transactional(rollbackFor = Exception.class)
    public void delByIds(int id) {
        baseMapper.deleteById(id);
    }


}
